package cc.wsyw126.java.nowcoder.sword_offer;

/**
 * Created by Administrator on 2017/4/13.
 */
public class FindGreatestSumOfSubArray {
    public int FindGreatestSumOfSubArray(int[] array) {
        int max = Integer.MIN_VALUE;
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            if (sum<=0) {
                sum=array[i];
            }else {
                sum+=array[i];
            }
            if (max<sum) max = sum;
        }
        return max;
    }

    public static void main(String[] args) {
        FindGreatestSumOfSubArray findGreatestSumOfSubArray = new FindGreatestSumOfSubArray();
        int i = findGreatestSumOfSubArray.FindGreatestSumOfSubArray(new int[]{-10, -2, -4, -1});
        System.out.println("i = " + i);
    }
}
